package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.dto.RoomAddNewDTO;
import cn.group.hotel2.pojo.dto.RoomUpdateDTO;
import cn.group.hotel2.pojo.entity.Room;
import cn.group.hotel2.pojo.vo.RoomListItemVO;
import cn.group.hotel2.pojo.vo.RoomStandardVO;
import cn.group.hotel2.pojo.vo.RoomUpdateVO;
import cn.group.hotel2.pojo.vo.TypeStandardVO;
import cn.group.hotel2.service.IRoomService;
import cn.group.hotel2.service.ITypeService;
import cn.group.hotel2.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private IRoomService roomService;

    @Autowired
    private ITypeService typeService;

    @GetMapping("/list/{currentPage}")
    public JsonResult<List<RoomListItemVO>> list(@PathVariable Integer currentPage){
        log.debug("页数:{}",currentPage);
        Integer current = (currentPage-1)*10;
        return JsonResult.ok(roomService.list(current));
    }

    @GetMapping("/count")
    public JsonResult<Integer> count(){
        return JsonResult.ok(roomService.getCount());
    }


    @PostMapping("/{id}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, RoomUpdateDTO roomUpdateDTO){
        roomService.updateById(id,roomUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id}")
    public JsonResult<RoomUpdateVO> getUpdateStandardById(@PathVariable Long id){
        return JsonResult.ok(roomService.getUpdateStandardById(id));
    }

    @PostMapping("/{id}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        roomService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/add-new")
    public JsonResult<Void> addNew(RoomAddNewDTO roomAddNewDTO){
        roomService.addNew(roomAddNewDTO);
        return JsonResult.ok();
    }

}
